class SeriesFormulaUtils(object):

    @staticmethod
    def cal_arithmetic_sequence_general_term_formula(begin_num, d, n):
        """
        等差数列的通项公式
        :param begin_num: 第一项
        :param d: 公差
        :param n: 第n项
        :return: 返回第n项的值
        """
        x = begin_num + (n - 1) * d
        return x

    @staticmethod
    def cal_proportional_sequence_general_term_formula(begin_num, q, n):
        """
        等比数列的通项公式
        :param begin_num: 第一项
        :param q: 公比
        :param n: 第n项
        :return: 返回第n项的值
        """
        x = begin_num * q ** (n - 1)
        return x

    @staticmethod
    def cal_sum_arithmetic_sequence(begin_num, n, d, an):
        """
        等差数列前n项和
        :param begin_num: 第一项
        :param n: 多少项
        :param d: 公差
        :param an: 最后一项
        """
        if d != 0 and an == 0:
            sum_result = n * begin_num + (n * (n - 1) * d) / 2
            print('等差数列前', n, '项和是', sum_result)
        elif d == 0 and an != 0:
            sum_result = (n * (begin_num + an)) / 2
            print('等差数列前', n, '项和是', sum_result)

    @staticmethod
    def cal_sum_proportional_sequence(begin_num, n, ratio):
        """
        等比数列前n项和
        :param begin_num: 第一项
        :param n: 多少项
        :param ratio: 公比
        """
        sum2 = begin_num * (1 - ratio ** n) / (1 - ratio)
        print('等比数列前', n, '项和是', sum2)

    @staticmethod
    def cal_average_capital(loan_amount, periods, ratio):
        """
        等额本金还款计算
        每期还款金额=贷款本金/还款期数 + (贷款本金-已还本金总额)*利率
        :param loan_amount: 贷款总金额
        :param periods: 还款期数
        :param ratio: 还款年利率
        """
        a1 = loan_amount / periods + loan_amount * (ratio / 12)
        a2 = loan_amount / periods + (loan_amount - loan_amount / periods) * (ratio / 12)
        d = a1 - a2
        sum_all = 0
        temp = a1
        i = 0
        while i < periods:
            sum_all = sum_all + temp
            temp = temp - d
            i = i + 1
        print('等额本金还款计算')
        print('首月还款是' + str(a1))
        print('每月还款减少' + str(d))
        print('总还款利息是' + str(sum_all - loan_amount))
        print('总还款金额是' + str(sum_all))

    @staticmethod
    def cal_average_capital_plus_interest(loan_amount, periods, ratio):
        """
        等额本息还款计算
        :param loan_amount:
        :param periods:
        :param ratio:
        """
        x = (loan_amount * ratio * (1 + ratio) ** periods) / ((1 + ratio) ** periods - 1)
        print('等额本息还款计算')
        print('每月还款金额是' + str(x))
        print('总还款利息是' + str(x * periods - loan_amount))
        print('总还款金额是' + str(x * periods))

    @staticmethod
    def cal_personal_income_tax(money):
        """
        2022个人所得税计算
        :param money: 个人月收入
        :return: 需缴税
        """
        tax = 0
        if money <= 5000:
            tax = 0
        elif 5000 < money <= 8000:
            tax = (money - 5000) * 0.03
        elif 8000 < money <= 17000:
            tax = 3000 * 0.03 + (money - 8000) * 0.1
        elif 17000 < money <= 30000:
            tax = 3000 * 0.03 + (17000 - 8000) * 0.1 + (money - 17000) * 0.2
        elif 30000 < money <= 40000:
            tax = 3000 * 0.03 + (17000 - 8000) * 0.1 + (30000 - 17000) * 0.2 + (money - 30000) * 0.25
        elif 40000 < money <= 60000:
            tax = 3000 * 0.03 + (17000 - 8000) * 0.1 + (30000 - 17000) * 0.2 + (40000 - 30000) * 0.25 + (
                    money - 40000) * 0.3
        elif 60000 < money <= 85000:
            tax = 3000 * 0.03 + (17000 - 8000) * 0.1 + (30000 - 17000) * 0.2 + (40000 - 30000) * 0.25 + (
                    60000 - 40000) * 0.3 + (money - 60000) * 0.35
        else:
            tax = 3000 * 0.03 + (17000 - 8000) * 0.1 + (30000 - 17000) * 0.2 + (40000 - 30000) * 0.25 + (
                    60000 - 40000) * 0.3 + (85000 - 60000) * 0.35 + (money - 85000) * 0.45
        return tax


if __name__ == '__main__':
    pass
    # SeriesFormulaUtils.cal_average_capital(5000, 12, 0.06)
    # SeriesFormulaUtils.cal_average_capital_plus_interest(5000, 12, 0.005)
    # SeriesFormulaUtils.cal_sum_proportional_sequence(10000, 10, 1.04)
    # SeriesFormulaUtils.cal_sum_arithmetic_sequence(1, 100, 0, 100)
    # SeriesFormulaUtils.cal_sum_arithmetic_sequence(1, 100, 1, 0)
    # print(SeriesFormulaUtils.cal_arithmetic_sequence_general_term_formula(12, 15, -5))
    # print(SeriesFormulaUtils.cal_proportional_sequence_general_term_formula(11, 0.3, 5))
